/**
 * Created by zhu on 2016/1/29.
 */
$(function(){
    var myhregf = window.location.href;
    var count = myhregf.split('/').length;
    var id = myhregf.split('/')[count-1];
    $.get(contextPath + "/category/child/"+id, function (data) {
        loadChild(data);
    });

    $.get(contextPath + "/category/leaf/"+id, function (data) {
        loadLeaf(data);
    });
});
function loadChild(data){
    data = jQuery.parseJSON(data);
    var  mydiv = $('#child_list');
    mydiv.empty();
    var tempDiv;
    $.each(data.list,function(i,item){
        var tempData;
        if(i%3 == 0){
            tempDiv = document.createElement("div");
            $(tempDiv).addClass("row choose");
            tempData= '<div class="col-33" style="margin-left: 2%;"> <a onclick="jumpNext('+item.id+')" class="button button-light">'+item.name+'</a></div>';

        }else{
            tempData= '<div class="col-33" style="margin-left: 2%;"> <a onclick="jumpNext('+item.id+')" class="button button-light">'+item.name+'</a></div>';
        }
        $(tempDiv).append(tempData);
        mydiv.append(tempDiv);
    });
}

function loadLeaf(data){
    data = jQuery.parseJSON(data);

    var hotGoodsDiv = $('#child_leaf');
    hotGoodsDiv.empty();
    var tempDiv;
    $.each(data.list,function(i,item){
        var mydiv;

        if(i%2 == 0){
            tempDiv = document.createElement("div");
            $(tempDiv).addClass("row hotGoods");
            mydiv = ' <div class="col-50"> ';
            mydiv += '<a onclick="productDetails('+item.id+')">';
            mydiv += '  <img src="'+contextPath+item.index_url+'" > ';
            mydiv += ' <div class="goodsTitle">'+item.name+'</div>  ';
            mydiv += '  <div class="description"><i class="fa fa-jpy">'+item.price+'</i></div></a></div> ';

        }else{
            mydiv = ' <div class="col-50"> ';
            mydiv += '<a onclick="productDetails('+item.id+')">';
            mydiv += '  <img src="'+contextPath+item.index_url+'" > ';
            mydiv += ' <div class="goodsTitle">'+item.name+'</div>  ';
            mydiv += '  <div class="description"><i class="fa fa-jpy">'+item.price+'</i></div></a> ';
            mydiv += '  </div> ';

        }
        $(tempDiv).append(mydiv);
        hotGoodsDiv.append(tempDiv);
    });
}